<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 6.3.0">
<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,400italic,700,700italic%7CZCOOL+QingKe+HuangYou:300,300italic,400,400italic,700,700italic%7CNoto+Sans+Simplified+Chinese:300,300italic,400,400italic,700,700italic%7CJetBrains+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="/lib/@fortawesome/fontawesome-free/css/all.min.css" integrity="sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8=" crossorigin="anonymous">
  <link rel="stylesheet" href="/lib/animate.css/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="/lib/@fancyapps/ui/dist/fancybox/fancybox.css" integrity="sha256-RvRHGSuWAxZpXKV9lLDt2e+rZ+btzn48Wp4ueS3NZKs=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"wyatex.online","root":"/","images":"/images","scheme":"Pisces","darkmode":true,"version":"8.18.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":false,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":true}}</script><script src="/js/config.js"></script>

    <meta name="description" content="老师发的复习题">
<meta property="og:type" content="article">
<meta property="og:title" content="Android复习题">
<meta property="og:url" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/index.html">
<meta property="og:site_name" content="Wyatex&#96;s blog">
<meta property="og:description" content="老师发的复习题">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/1.png">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/2.jpg">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/3.png">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/4.jpg">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/5.jpg">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/6.png">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/7.png">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/8.jpg">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/9-1.jpg">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/9-2.jpg">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/9-3.jpg">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/10.png">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/11-1.jpg">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/11-2.jpg">
<meta property="og:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/12-1.jpg">
<meta property="article:published_time" content="2020-12-24T05:09:38.000Z">
<meta property="article:modified_time" content="2023-05-05T01:25:46.907Z">
<meta property="article:author" content="Wyatex">
<meta property="article:tag" content="Android">
<meta property="article:tag" content="复习题">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/1.png">


<link rel="canonical" href="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/","path":"复习题/Android复习题/","title":"Android复习题"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Android复习题 | Wyatex`s blog</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Wyatex`s blog</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">97</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">26</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">155</span></a></li><li class="menu-item menu-item-编程"><a href="/programming/" rel="section"><i class="fa fa-book fa-fw"></i>编程</a></li><li class="menu-item menu-item-蹲坑读物"><a href="/%E5%B9%B2%E8%B4%A7/%E5%BC%80%E5%8F%91%E4%BA%A4%E6%B5%81%E7%BE%A4%E5%88%86%E4%BA%AB%E8%AE%B0%E5%BD%95/" rel="section"><i class="fa fa-book fa-fw"></i>蹲坑读物</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%80%89%E6%8B%A9%E9%A2%98"><span class="nav-number">1.</span> <span class="nav-text">选择题</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%A1%AB%E7%A9%BA%E9%A2%98"><span class="nav-number">2.</span> <span class="nav-text">填空题</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BD%9C%E5%93%81%E9%A2%98"><span class="nav-number">3.</span> <span class="nav-text">作品题</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Wyatex"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Wyatex</p>
  <div class="site-description" itemprop="description">这里是我用来做笔记的网站哟~</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">155</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">26</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">97</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/wyatex" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wyatex" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:wyatex@qq.com" title="E-Mail → mailto:wyatex@qq.com" rel="noopener me" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
    <div class="sidebar-inner sidebar-blogroll">
      <div class="links-of-blogroll animated">
        <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
          链接
        </div>
        <ul class="links-of-blogroll-list">
            <li class="links-of-blogroll-item">
              <a href="https://antfu.me/" title="https:&#x2F;&#x2F;antfu.me&#x2F;" rel="noopener" target="_blank">Anthony Fu</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://www.codesky.me/" title="https:&#x2F;&#x2F;www.codesky.me&#x2F;" rel="noopener" target="_blank">CodeSky</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://learn.lianglianglee.com/" title="https:&#x2F;&#x2F;learn.lianglianglee.com&#x2F;" rel="noopener" target="_blank">技术文章摘抄</a>
            </li>
        </ul>
      </div>
    </div>
        <div class="pjax">
        <div class="sidebar-inner sidebar-post-related">
          <div class="animated">
              <div class="links-of-blogroll-title"><i class="fa fa-signs-post fa-fw"></i>
    相关文章
  </div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/%E5%AE%89%E5%8D%93/%E5%AE%89%E5%8D%93%E5%BC%80%E5%8F%91%E4%B9%8BJetpack%EF%BC%9ALifeCycle/" rel="bookmark">
        <time class="popular-posts-time">2021-05-31</time>
        <br>
      安卓开发之Jetpack：LifeCycle
      </a>
    </li>
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/Flutter/Ubuntu%E6%90%AD%E5%BB%BAFlutter%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/" rel="bookmark">
        <time class="popular-posts-time">2022-10-23</time>
        <br>
      Ubuntu搭建Flutter开发环境
      </a>
    </li>
  </ul>

          </div>
        </div>
        </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Wyatex">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Wyatex`s blog">
      <meta itemprop="description" content="这里是我用来做笔记的网站哟~">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Android复习题 | Wyatex`s blog">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Android复习题
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-12-24 13:09:38" itemprop="dateCreated datePublished" datetime="2020-12-24T13:09:38+08:00">2020-12-24</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-05-05 09:25:46" itemprop="dateModified" datetime="2023-05-05T09:25:46+08:00">2023-05-05</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%A4%8D%E4%B9%A0%E9%A2%98/" itemprop="url" rel="index"><span itemprop="name">复习题</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>老师发的复习题</p>
<span id="more"></span>

<h1 id="选择题"><a href="#选择题" class="headerlink" title="选择题"></a>选择题</h1><ol>
<li><p>   下列哪些语句关于内存回收的说明是正确的?(  B  )<br>A、	程序员必须创建一个线程来释放内存<br>B、	内存回收程序负责释放无用内存<br>C、	内存回收程序允许程序员直接释放内存<br>D、	内存回收程序可以在指定的时间释放内存对象 </p>
</li>
<li><p>   Android 中下列属于 Intent 的作用的是(  C  )<br>A、	实现应用程序间的数据共享<br>B、	是一段长的生命周期，没有用户界面的程序，可以保持应用在后台运行，而不会因为切换页面而消失<br>C、	可以实现界面间的切换，可以包含动作和动作数据，连接四大组件的纽带<br>D、	处理一个应用程序整体性的工作 </p>
</li>
<li><p>   下面在 AndroidManifest.xml 文件中注册 BroadcastReceiver 方式正确的(  A  )    </p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">A、 <span class="tag">&lt;<span class="name">receiver</span> <span class="attr">android:name</span>=<span class="string">&quot;NewBroad&quot;</span>&gt;</span> </span><br><span class="line">        <span class="tag">&lt;<span class="name">intent-filter</span>&gt;</span> </span><br><span class="line">            <span class="tag">&lt;<span class="name">action</span>   </span></span><br><span class="line"><span class="tag">                <span class="attr">android:name</span>=<span class="string">&quot;android.provider.action.NewBroad&quot;</span>/&gt;</span> </span><br><span class="line">            <span class="tag">&lt;<span class="name">action</span>&gt;</span> </span><br><span class="line">        <span class="tag">&lt;/<span class="name">intent-filter</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;/<span class="name">receiver</span>&gt;</span> </span><br><span class="line">B、	<span class="tag">&lt;<span class="name">receiver</span> <span class="attr">android:name</span>=<span class="string">&quot;NewBroad&quot;</span>&gt;</span> </span><br><span class="line">        <span class="tag">&lt;<span class="name">intent-filter</span>&gt;</span> </span><br><span class="line">            android:name=&quot;android.provider.action.NewBroad&quot;/&gt; </span><br><span class="line">        <span class="tag">&lt;/<span class="name">intent-filter</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;/<span class="name">receiver</span>&gt;</span> </span><br><span class="line">C、	<span class="tag">&lt;<span class="name">receiver</span> <span class="attr">android:name</span>=<span class="string">&quot;NewBroad&quot;</span>&gt;</span> </span><br><span class="line">        <span class="tag">&lt;<span class="name">action</span>   </span></span><br><span class="line"><span class="tag">            <span class="attr">android:name</span>=<span class="string">&quot;android.provider.action.NewBroad&quot;</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">action</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;/<span class="name">receiver</span>&gt;</span> </span><br><span class="line">D、	<span class="tag">&lt;<span class="name">intent-filter</span>&gt;</span> </span><br><span class="line">        <span class="tag">&lt;<span class="name">receiver</span> <span class="attr">android:name</span>=<span class="string">&quot;NewBroad&quot;</span>&gt;</span> </span><br><span class="line">            <span class="tag">&lt;<span class="name">action</span>&gt;</span>  </span><br><span class="line">                android:name=&quot;android.provider.action.NewBroad&quot;/&gt; </span><br><span class="line">            <span class="tag">&lt;<span class="name">action</span>&gt;</span> </span><br><span class="line">        <span class="tag">&lt;/<span class="name">receiver</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;/<span class="name">intent-filter</span>&gt;</span> </span><br></pre></td></tr></table></figure>
</li>
<li><p>   关于 ContenValues 类说法正确的是(  D  )<br>A、	他和 Hashtable 比较类似，也是负责存储一些名值对，但是他存储的名值对当中的名是任意类型，而值都是基本类型<br>B、	他和 Hashtable 比较类似，也是负责存储一些名值对，但是他存储的名值对当中的名，可以为空，而值都是 String 类型<br>C、	他和 Hashtable 比较类似，也是负责存储一些名值对，但是他存储的名值对当中的名是String 类型，而值也是 String 类型<br>D、	他和 Hashtable 比较类似，也是负责存储一些名值对，但是他存储的名值对当中的名是String 类型，而值都是基本类型 </p>
</li>
<li><p>   下面退出 Activity 错误的方法是(  C  )<br>A、	finish() B、抛异常强制退出 	C、System.exit()  	D、onStop() </p>
</li>
<li><p>   下面关于 Android dvm 的进程和 Linux 的进程,应用程序的进程说法正确的是(  D  )<br>A、	DVM 指 dalivk 的虚拟机.每一个 Android 应用程序都在它自己的进程中运行,不一定拥有一个独立的 Dalvik 虚拟机实例.而每一个 DVM 都是在 Linux 中的一个进程,所以说可以认为是同一个概念.<br>B、	DVM 指 dalivk 的虚拟机.每一个 Android 应用程序都在它自己的进程中运行,不一定拥有一个独立的 Dalvik 虚拟机实例.而每一个 DVM 不一定都是在 Linux 中的一个进程,所以说不是一个概念.<br>C、	DVM 指 dalivk 的虚拟机.每一个 Android 应用程序都在它自己的进程中运行,都拥有一个独立的 Dalvik 虚拟机实例.而每一个 DVM 不一定都是在 Linux 中的一个进程,所以说不是一个概念.<br>D、	DVM 指 dalivk 的虚拟机.每一个 Android 应用程序都在它自己的进程中运行,都拥有一个独立的 Dalvik 虚拟机实例.而每一个 DVM 都是在 Linux 中的一个进程,所以说可以认为是同一个概念. </p>
</li>
<li><p>   Android 项目工程下面的 assets 目录的作用是什么(  B  )<br>A、	放置应用到的图片资源。 	 	 	  B、主要放置多媒体等数据文件<br>C、放置字符串，颜色，数组等常量数据   D、放置一些与 UI 相应的布局文件，都是 xml 文件 </p>
</li>
<li><p>   关于 res&#x2F;raw 目录说法正确的是(  A  )<br>A、	这里的文件是原封不动的存储到设备上不会转换为二进制的格式<br>B、	这里的文件是原封不动的存储到设备上会转换为二进制的格式<br>C、	这里的文件最终以二进制的格式存储到指定的包中<br>D、	这里的文件最终不会以二进制的格式存储到指定的包中 </p>
</li>
<li><p>   Android 是如何组织 Activity 的(  A  )<br>A、	以栈的方式组式 Activity 	 	 	B、 以队列的方式组织 Activity<br>C、 以树形方式组织 Activity 	 	 	D、 以链式方式组织 Activity。 </p>
</li>
<li><p>   onPause 什么时候调用(  C  )<br> A．当界面启动时  	 	 	 	 	B．当 onCreate 方法被执行之后<br> C．当界面被隐藏时 	 	 	 	 	D．当界面重新显示时 </p>
</li>
<li><p>   在 Activity 中，如何获取 service 对象(  A  )<br> A．可以通过直接实例化得到。  	 	B．可以通过绑定得到。<br> C．通过 startService() 	 	 	 	D．通过 getService()获取。 </p>
</li>
<li><p>   在表格布局中，android:collapseColumns&#x3D;”1,2”的含义是( C )<br>A、	在屏幕中，当表格的列能显示完时，显示1，2列<br>B、	在屏幕中，当表格的列显示不完时，折叠<br>C、在屏幕中，不管是否能都显示完，折叠1、2列<br>D、在屏幕中,动态决定是否显示表格。 </p>
</li>
<li><p>   绝对布局中，android:layout_x 的含义有( B )<br>A、	以手机左下为原点，组件显示到屏幕中的横向坐标值。<br>B、	以手机左上为原点，组件显示到屏幕中的横向坐标值。<br>C、以手机右下为原点，组件显示到屏幕中的横向坐标值。<br>D、以手机右下为原点，组件显示到屏幕中的横向坐标值。 </p>
</li>
<li><p>   创建 Menu 需要重写的方法是( C )<br>A、	onOptionsCreateMenu（Menu menu）<br>B、onOptionsCreateMenu（MenuItem menu）<br>C、onCreateOptionsMenu(Menu menu) 	<br>D、onCreateOptionsMenu(MenuItem menu) </p>
</li>
<li><p>   在使用 SQLiteOpenHelper 这个类时，它的哪一个方法是用来实现版本升级之用的( D )<br>A．onCreate()  B．onCreade()  C．onUpdate()  D． onUpgrade() </p>
</li>
<li><p>   ScrollView 中，可以直接包含多少个组件( B )<br> A．三个 B．两个  C．一个 D．无数个</p>
</li>
<li><p>TabHost.newTabSpec(“tab1”)( B ) 	<br>A．为 tab 页创建标题为 tab1 	 B．为 tab 页创建 ID 为 tab1<br>C．为 tab 页创建内容  	D．为 tab 页创建新空格</p>
</li>
<li><p>关于适配器的说法正确的有( B ) 	<br>A．它主要是用来存储数据  	 	 	 	B．它主要用来把数据绑定到组件上<br>C．它主要用来解析数据   	 	 	 D．它主要用来存储 xml 数据</p>
</li>
<li><p>关于 Activity 说的法不正确的是( C ) 	<br>A． Activity 是为用户操作而展示的可视化用户界面<br>B． 一个应用程序可以有若干个 Activity<br>C． Activity 可以通过一个别名去访问<br>D． Activity 可以表现为一个漂浮的窗口 </p>
</li>
<li><p>   service 中如何实现更改 Activity 界面元素( B )<br>A．通过把当前 actvity 对象传递给 service 对象。<br>B．通过向 Activity 发送广播。<br>C．通过 Context 对象更改 Act]ivity 界面元素<br>D．可以在 service 中，调用 Activity 的方法实现更改界面元素。 </p>
</li>
<li><p>   激活 Activity 的方法是( C )<br> A．runActivity()  	B．goActivity() 	 	C．startActivity()  	D．startActivityForIn() </p>
</li>
<li><p>   关于 android 进程，说法不正确的是( C )<br>A．组件运行所在的进程，是由 androidmanifest.xml 决定，它可以指定该组件运行于哪个进程。<br>B、当急需内存时，android 会决定优先关闭那些空闲的进程<br>C．背景进程是不为用户所见的 Activity，但是还会有可能被用户看到，所以它不能被杀死<br>D．可视进程一般不会不被系统所杀死 </p>
</li>
<li><p>   在 Activity 的生命周期中，当它从可见状态转向半透明状态时，它的哪个方法必须被调用( B )<br>A．onStop()   B．onPause()   C．onRestart()   D．onStart() </p>
</li>
<li><p>   当 Activity 被消毁时，如何保存它原来的状态( A )<br>A．实现 Activity 的 onSaveInstanceState()方法<br>B．实现 Activity 的 onSaveInstance()方法<br>C．实现 Activity 的 onInstanceState()方法<br>D． 实现 Activity 的 onSaveState()方法 </p>
</li>
<li><p>   关于 Intent 对象说法错误的是( D )<br>A．在 android 中，Intent 对象是用来传递信息的<br>B．Intent 对象可以把值传递给广播或 Activity<br>C．利用 Intent 传值时，可以传递一部分值类型<br>D．利用 Intent 传值时，它的 key 值可以是对象 </p>
</li>
<li><p>   在 android 中，ArrayAdapter 类是用于( A )<br>A．用于把数据绑定到组件上<br>B．它能把数据显示到 Activity 上<br>C．它能把数据传递给广播<br>D．它能把数据传递给服务 </p>
</li>
<li><p>   使进度条变横向的系统样式是( A )<br>A.	@android:style&#x2F;Widget.ProgressBar.Horizontal<br>B.	@android:style&#x2F;ProgressBar.Horizontal<br>C.	@style&#x2F;Widget.ProgressBar.Horizontal<br>D.	@style&#x2F;ProgressBar.Horizontal </p>
</li>
<li><p>   activity 对一些资源以及状态的操作保存，最好是保存在生命周期的哪个函数中进行( D )<br>A.	onPause()  	 	B、onCreate()   	C、 onResume()  	D、onStart()</p>
</li>
<li><p>下面哪一个不属于 Android 体系结构中的应用程序层( C ) 		<br>A、电话簿 	 	 	B、日历  	 	 	C、SQLite 	 	 	D、SMS 程序 </p>
</li>
<li><p>   下面哪种说法不正确( B )<br>A、	Android 应用的 gen 目录下的 R.java 被删除后还能自动生成;<br>B、	res 目录是一个特殊目录，包含了应用程序的全部资源，命名规则可以支持数字(0-9)下横线<br>(_),大小写字母(a-z , A-Z);<br>C、	AndroidManifest.xml 文件是每个 Android 项目必须有的，是项目应用的全局描述。其中指定程序的包名(package&#x3D;”…”)+指定 android 应用的某个组件的名字(android:name&#x3D;”…”)组成了该组件类的完整路径<br>D、	assets 和 res 目录都能存放资源文件，但是与 res 不同的是 assets 支持任意深度的子目录，在它里面的文件不会在 R.java 里生成任何资源 ID </p>
</li>
<li><p>   在一个相对布局中怎样使一个控件居中( C )<br>A、android:gravity&#x3D;”center”  	 	 	 	B、android:layout_gravity&#x3D;”center”<br>C、android:layout_centerInParent&#x3D;”true” 	D、android:scaleType&#x3D;”center” </p>
</li>
<li><p>   下列说法哪个不正确( C )<br>A、	拥有 android:configChanges&#x3D;”orientation|keyboardHidden”标签的 Activity 在横竖屏转换时不会再执行 onCreate 方法<br>B、	默认情况下对一个 Activity 的对象进行横竖屏切换，该对象的 onCreate 方法在每次切换时都会执行<br>C、	一个 Activity 的对象 a1上弹出了一个模拟对话框形式的 Activity 的对象 a2，按返回键后 a1 执行了 onStart 和 onResume 方法,a2执行了 onPause,onStop 和 onDestroy 方法<br>D、	一个界面上的 EditText 中输入文字后，再按下 Home，该界面消失，等再回到该界面文字内容仍在，onCreate 方法也不会执行 </p>
<blockquote>
<p>a1调用OnResume，a2调用了OnStop</p>
</blockquote>
</li>
<li><p>   下列关于 Service 的描述，正确的是( D )<br>A．Servie 主要负责一些耗时比较长的操作，这说明 Service 会运行在独立的子线程中<br>B．每次调用 Context 类中的 StartService()方法后都会新建一个 Service 实例<br>C．每次启动一个服务时候都会先后调用 onCreate()和 onStart()方法<br>D．当调用了 ConText 类中的 StopService()方法后，Serviece 中的 onDestroy()方法会自动回调 </p>
</li>
<li><p>   在 Android 中使用 Menu 时可能需要重写的方法有( AC )。[多选]<br>A、onCreateOptionsMenu() 	 	 	B、onCreateMenu()<br>C、onOptionsItemSelected() 	 	 	D、onItemSelected() </p>
</li>
<li><p>   在 Android 中使用 SQLiteOpenHelper 这个辅助类时，可以生成一个数据库，并可以对数据库版本进行管理的方法可以是( AB )[多选]<br>A、	getWriteableDatabase() 	 	 	B、getReadableDatabase()<br>C、getDatabase()  	 	 	 	 	D、getAbleDatabase() </p>
</li>
<li><p>   Android 关于 service 生命周期的 onCreate()和 onStart()说法正确的是( AD )[多选]<br>A、	当第一次启动的时候先后调用 onCreate()和 onStart()方法<br>B、	当第一次启动的时候只会调用 onCreate()方法<br>C、	如果 service 已经启动，将先后调用 onCreate()和 onStart()方法<br>D、	如果 service 已经启动，只会执行 onStart()方法，不再执行 onCreate()方法 </p>
</li>
<li><p>   下列属于 Activity 的状态是( ABC )[多选]<br>A.运行状态  B 暂停状态 C 停止状态  D 睡眠状态 </p>
</li>
<li><p>关于 Handler 的说话正确的是( AB )[多选] 	<br>A.它实现不同线程间通信的一种机制 	 	B.它避免了新线程操作 UI 组件<br>C.它采用栈的方式来组织任务的 	 	 	D.它可以属于一个新的线程 </p>
</li>
<li><p>   关于广播的作用，正确的说法是( ABCD ) [多选]<br>A 它是用接收系统发布的一些消息的 	 	B 它可以帮助 service 修改用户界面<br>C 它可以启动一个 Activity  	 	 	 	D 它可以启动一个 Service </p>
</li>
<li><p>   下面属于 View 的子类的是( CD ) [多选]<br>A	Activity 	 	 	B Service 	 	 	C ViewGroup 	 	D TextView </p>
</li>
<li><p>   在 main.xml 中，定义一个组件时，有两个属性必须写( AB ) [多选]<br>A android:layout_width   B android:layout_height<br>C android:id&#x3D;”@+id&#x2F;start” D android:text </p>
</li>
<li><p>   请找出你学过的适配器类( AC ) [多选]<br>A	SimpleAdapter  	 	 	 	 	 	B SimpleArrayAdapter<br>C SimpleCursorAdapter 	 	 	 	 	D SimpleCursorsAdapter </p>
</li>
<li><p>   关于 Sqlite 数据库，正确的说法( ABD ) [多选]<br>A	SqliteOpenHelper 类主要是用来创建数据库和更新数据库<br>B	SqliteDatabase 类是用来操作数据库的<br>C	在每次调用 SqliteDatabase 的 getWritableDatabase()方法时，会执行 SqliteOpenHelper 的 onCreate 方法。<br>D	当数据库版本发生变化时，可以自动更新数据库结构 </p>
</li>
<li><p>   Intent 传递数据时，下列的数据类型哪些可以被传递( ABCD )[多选]<br>A	Serializable    	B、charsequence   C、Parcelable    	D、Bundle </p>
</li>
<li><p>   下列不属于 service 生命周期的方法是( CD )<br>A,onCreate<br>B,onDestroy<br>C,onStop<br>D,onStart </p>
<blockquote>
<p>service生命周期：onCreat()、onStartCommand()、onDestroy()、onBind()、onUnbind()</p>
</blockquote>
</li>
<li><p>   在 android 中使用 RadioButton 时，要想实现互斥的选择需要用的组件是( D )<br>A,ButtonGroup  B, RadioButtons  C,CheckBox  D,RadioGroup </p>
</li>
<li><p>   创建子菜单的方法是( B )<br>A,add 	B,addSubMenu C,createSubMenu 	D,createMenu </p>
</li>
<li><p>   处理菜单项单击事件的方法不包含( D )<br>A,使用 onOptionsItemSelected(MenuItem item)响应<br>B,使用 onMenuItemSelected(int featureId ,MenuItem item) 响应<br>C,使用 onMenuItemClick(MenuItem item) 响应<br>D,使用 onCreateOptionsMenu(Menu menu)响应 </p>
</li>
<li><p>   关于 AlertDialog 的说法不正确的是( A )<br>A,要想使用对话框首先要使用 new 关键字创建 AlertDialog 的实例<br>B,对话框的显示需要调用 show 方法<br>C,setPositiveButton 方法是用来加确定按钮的<br>D,setNegativeButton 方法是用来加取消按钮的 </p>
</li>
<li><p>   上下文菜单与其他菜单不同的是( B )<br>A,上下文菜单项上的单击事件可以使用 onMenuItemSelected 方法来响应<br>B,上下文菜单必须注册到指定的 view 上才能显示<br>C,上下文菜单的菜单项可以添加，可以删除<br>D,上下文菜单的菜单项可以有子项 </p>
</li>
<li><p>   以下关于 Android 应用程序的目录结构描述中，不正确的是？( D )<br>A、 src 目录是应用程序的主要目录，由 Java 类文件文件组成<br>B、	assets 目录是原始资源目录，该目录中的内容将不会被 R 类所引用<br>C、	res 目录是应用资源目录，该目录中的所有资源内容都会被 R 类所索引<br>D、	AndroidManifest.xml 文件是应用程序目录清单文件，该文件由 ADT 自动生成，不需要程序员手动修改   </p>
</li>
<li><p>对于 XML 布局文件中的视图控件，layout_width 属性的属性值不可以是什么？ ( D )<br>a. match_parent<br>b. fill_parent<br>c. wrap_content<br>d. match_content</p>
</li>
<li><p>关于 BroadcastReceiver 的说法不正确的是？  ( B )<br>a. 是用来接收广播 Intent 的<br>b. 一个广播 Intent 只能被一个订阅了此广播的 BroadcastReceiver 所接收<br>c. 对有序广播，系统会根据接收者声明的优先级别按顺序逐个执行接收者<br>d. 接收者声明的优先级别在的 android:priority 属性中声明，数值越大 优先级别越高 </p>
</li>
<li><p>关于 Sqlite 数据库，不正确的说法是（ C ） 选择一项：<br>a. SqliteOpenHelper 类主要是用来创建数据库和更新数据库<br>b. SqliteDatabase 类是用来操作数据库的<br>c. 在每次调用 SqliteDatabase 的 getWritableDatabase() 方法时，会执行 teOpenHelper 的 onCreate 方法。<br>d. 当数据库版本发生变化时，可以自动更新数据库结构 </p>
</li>
<li><p>下列对 SharePreferences 存、取文件的说法中正确的是：ABD<br>A,属于移动存储解决方案     B,sharePreferences处理的就是key-value对<br>C,读取xml文件的路径是&#x2F;sdcard&#x2F;shared_prefx  D,信息的保存格式是xml </p>
</li>
<li><p>android 数据存储与访问的方式有？( ABCD )<br>a.	sharedpreference 	<br>b.	数据库 	<br>c.	文件 	<br>d.	内容提供者 	  </p>
</li>
<li><p>下列说法正确的有（ABC）<br>A. javac.exe 能指定编译结果要置于哪个目录（directory）<br>B. 在编译程序时，所能指定的环境变量不包括class path<br>C. javac 一次可同时编译数个java 源文件<br>D. 环境变量可在编译source code时指定</p>
</li>
<li><p>下列说法错误的有（BCD）<br>A. Java语言中的方法必定隶属于某一类（对象），调用方法与过程或函数相同<br>B. Java面向对象语言容许单独的过程和函数存在<br>C. Java面向对象语言容许单独的方法存在<br>D. Java语言中的方法属于类的成员（member） </p>
</li>
<li><p>解析 xml 的方式有（CD）<br>A. 字符器类型<br>B. 流方式<br>C. DOM<br>D. SAX</p>
</li>
<li><p>Intent传递数据时，下列的哪种类型数据不可以被传递？B<br>A. Serializable<br>B. JSON对象<br>C. Bundle<br>D. Charsequence</p>
</li>
<li><p>在多个应用中读取共享存储数据时， 需要用到哪个对象的 query 方法？A<br>A. ContentResolver<br>B. ContentProvider<br>C. Cursor<br>D. SQLiteHelper</p>
</li>
<li><p>下列说法正确的是？A<br>A. 每个进程都运行于自己的 java 虚拟机(JVM)中。<br>B. 默认情况下，每个应用程序中均运行于自己的进程中，而且此进程不会被消毁。<br>C. 每个应用程序会被赋予一个唯一的 linux 用户 ID，从而使得该应用程序下的文件， 其它用户也可以访问。<br>D. 一个应用程序数据，可以随意被其它应用程序所访问</p>
</li>
<li><p>使用 AIDL 完成远程 service 方法调用下列说法不正确的是？A<br>选择一项：<br>A. aidl 对应的接口名称不能与 aidl 文件名相同<br>B. aidl 的文件的内容类似 java 代码<br>C. 创建一个 Service（服务），在服务的 onBind(Intent intent)方法中返回实现了 aidl 接口的对象<br>D. aidl 对应的接口的方法前面不能加访问权限修饰符</p>
</li>
<li><p>关于视图控件的常用事件描述中，不正确的是？A<br>A. Click事件只能使用在按钮上，表示按钮的点击动作<br>B. 当TextView类视图控件失去焦点或获得焦点时，将触发FocusChange事件<br>C. 当单选框中某一选项被选择时，将触发CheckedChange事件<br>D. 当多选框中某一选项被选择时，将触发CheckedChange事件</p>
</li>
<li><p>下列说法正确的有（C）<br>A．class中的constructor不可省略<br>B．constructor必须与class同名，但方法不能与class同名<br>C．constructor在一个对象被new时执行<br>D．一个class只能定义一个constructor</p>
</li>
<li><p>下列语句哪一个正确（B）<br>A．Java程序经编译后会产生machine code<br>B．Java程序经编译后会产生byte code<br>C．Java程序经编译后会产生DLL<br>D．以上都不正确</p>
</li>
<li><p>下列属于SAX解析xml文件的优点是（B）<br>A．将整个文档树存储在内存中，便于操作，支持删除，修改，重新排列等多种功能（DOM）<br>B．不用事先调入整个文档，占用资源少<br>C．整个文档调入内存，浪费时间和空间<br>D．不是长久驻留在内存，数据不是持久的，事件过后，若没有保存数据，数据就会消失</p>
</li>
<li><p>DDMS中Log信息分为几个级别（C）<br>A．3<br>B．4<br>C．5<br>D．7</p>
</li>
<li><p>Android下的单元测试要配置，以下说法不正确的是（A）<br>A．需要在manifest.xml清单文件application节点下配置instrumentation<br>B．需要在manifest.xml清单文件manifest节点下配置instrumentation<br>C．需要在manifest.xml清单文件application节点下配置uses-library<br>D．需要让测试类继承AndroidTestCase类</p>
</li>
<li><p>下列说法错误的一项是（D）<br>A．Button是普通按钮组件，除此之外还有其他的按钮组件<br>B．TextView是显示文本的组件，TextView是EditText的父类<br>C．EditText是编辑文本的组件，可以使用EditText输入特定的字符<br>D．ImageView是显示图片的组件，可以通过设置显示局部图片</p>
</li>
<li><p>下列关于XML布局文件在Java代码中被引用的说明中，不正确的是（B）<br>A．在Activity中，可以使用findViewById( )方法，通过资源id，获得指定视图元素<br>B．在Activity中，可以使用R.drawable-system.***方式引用Android系统所提供的图片资源<br>C．在Activity中，可以使用setContentView( )方法，确定加载哪一个布局文件<br>D．可以使用View类的findViewById( )方法，获得当前View对象中的某一个视图元素</p>
</li>
</ol>
<h1 id="填空题"><a href="#填空题" class="headerlink" title="填空题"></a>填空题</h1><p>1、 Android 中常用的五种布局是 <strong>FrameLayout，LinearLayout，RelativeLayout，AbsoluteLayout 和 TableLayout</strong> 。<br>2、 Android 的四大组件是 <strong>activity，service，broadcast 和 contentprovide</strong>。<br>3、 Android 中 service 的实现方法是：<strong>startservice 和 bindservice</strong>。<br>4、 activity 一般会重载 7 个方法用来维护其生命周期，除了 <strong>onCreate(),onStart(),onDestory()</strong> 外还有 <strong>onrestart,onresume,onpause,onstop</strong>。<br>5、 android 的数据存储的方式 <strong>sharedpreference</strong>，文件，<strong>SQlite,contentprovider</strong>，网络。<br>6、 当启动一个Activity并且新的 Activity执行完后需要返回到启动它的 Activity来执行的回调函数是 <strong>startActivityResult()</strong> 。<br>7、 属于 android 中的三种适配器 <strong>SimpleAdapter、ArrayAdapter、 BaseAdapter</strong> 。<br>8、 元素中 layout_width 的取值有 <strong>wrap_content</strong> 、match_parent、fill_parent。<br>9、 SQLite 支持五种数据类型包括 <strong>TEXT</strong> 、NULL、BLOB、REAL、INTEGER。<br>10、一个 Activity 就是一个<strong>可视化的界面</strong>或者看成是控件的容器。<br>11、onPause()方法在 activity 被暂停或收回 CPU 和其他资源时调用，该方法用于<strong>保存活动状态的</strong>，也是对运行时数据的现场保护。<br>12、onDestroy 是 activity 被干掉前最后一个被调用方法，当调用 <strong>finish</strong> 方法或者系统为了节省空间将它暂时性的干掉时候调用。<br>13、使用 <strong>startService()</strong> 方法启动服务后，调用者和服务间没有关联，即使调用者退出了，服务仍然进行。<br>14、当应用程序中某广播在 AndroidMainifest.xml 进行注册后，即使该应用程序关闭后，也可以接受操作系统发出的 <strong>广播信息</strong> 。<br>15、定义 LinearLayout 水平方向布局时至少设置的三个属性：<strong>android:orientation</strong>， <strong>android:layout width 和 android:layout height</strong><br>16、Android 平台提供了 2D，3D 的图形支持，<strong>SQLite</strong> 数据库支持，并且集成了浏览器<br>17、Android SDK 主要以 <strong>java</strong> 语言为基础。<br>18、Android.jar 是一个标准的压缩包，其内容包含的是编译后的 <strong>class</strong>，包含了全部的 <strong>API</strong>。</p>
<h1 id="作品题"><a href="#作品题" class="headerlink" title="作品题"></a>作品题</h1><ol>
<li><p>导入“TextViewDemo”的安卓程序，建立如下图所示的界面，界面包含 TextView(id:TextView01)和 EditText(id:EditText01)两个控件，请分别在 main.xml 和 TextViewDemoActivity.java 补充程序：</p>
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/1.png" class="">
<p>在XML文件里：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/TextView01&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;User:&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">EditText</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;fill_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/EditText01&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>导入“ButtonDemo”的安卓程序，建立如下图所示的界面，界面包含 TextView(id:TextView01)、Button(id:Button01)和 ImageButton(id:  ImageButton01)两个按钮，上方是“Button 按钮”，下方是一个 ImageButton 控件，请分别在 main.xml 和 ButtonDemoActivity.java 补充程序：</p>
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/2.jpg" class="">
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/TextView01&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;ButtonDemo&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;Button&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/Button01&quot;</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">ImageButton</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/ImageButton01&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:src</span>=<span class="string">&quot;@drawable/xxx.xxx&quot;</span>  /&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>导入“ListViewDemo”的安卓程序，建立如下图所示的界面，界面包含 TextView(id:TextView01) 和 ListView01 (id: ListView01)两个按钮，ListView01 中所显示的内容“ListView 子项 1、ListView 子项 2 ListView 子项 3”并单击相应菜单项时 TextView 显示相应菜单名称，请分别在 main.xml 和ButtonDemoActivity.java 补充程序：</p>
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/3.png" class="">
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/TextView01&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;ListViewDemo!&quot;</span> /&gt;</span></span><br><span class="line">    </span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">ListView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/ListView01&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">TextView</span> <span class="variable">textView</span> <span class="operator">=</span> findViewById(R.id.TextView01);</span><br><span class="line"><span class="type">ListView</span> <span class="variable">listView</span> <span class="operator">=</span> findViewById(R.id.ListView01);</span><br><span class="line">String[] list = &#123;<span class="string">&quot;ListView子项1&quot;</span>, <span class="string">&quot;ListView子项2&quot;</span>, <span class="string">&quot;ListView子项3&quot;</span>&#125;;</span><br><span class="line"></span><br><span class="line">ArrayAdapter&lt;String&gt; adapter = <span class="keyword">new</span> <span class="title class_">ArrayAdapter</span>&lt;String&gt;(<span class="built_in">this</span>, android.R.layout.simple_list_item_1, list);</span><br><span class="line">listView.setAdapter(adapter);</span><br><span class="line"></span><br><span class="line">AdapterView.<span class="type">OnItemClickListener</span> <span class="variable">onClickListener</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">AdapterView</span>.OnItemClickListener() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onItemClick</span><span class="params">(AdapterView&lt;?&gt; parent, View view, <span class="type">int</span> position, <span class="type">long</span> id)</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (position == <span class="number">0</span>) &#123;</span><br><span class="line">            textView.setText(<span class="string">&quot;点击了ListView子项1&quot;</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (position == <span class="number">1</span>) &#123;</span><br><span class="line">            textView.setText(<span class="string">&quot;点击了ListView子项2&quot;</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            textView.setText(<span class="string">&quot;点击了ListView子项3&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br><span class="line">listView.setOnItemClickListener(onClickListener);</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建工程，命名为 LinearLayoutDemo，布局界面如图，A、B、C 三个按钮呈垂直线性排列，请写出相关布局文件代码。</p>
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/4.jpg" class="">
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">LinearLayout</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;fill_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;fill_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:orientation</span>=<span class="string">&quot;vertical&quot;</span> &gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:text</span>=<span class="string">&quot;A&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_gravity</span>=<span class="string">&quot;center&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:text</span>=<span class="string">&quot;B&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_gravity</span>=<span class="string">&quot;center&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:text</span>=<span class="string">&quot;C&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_gravity</span>=<span class="string">&quot;center&quot;</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">LinearLayout</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>创建工程，命名为 TableLayoutDemo，布局界面如图，组件请使用表格布局排列，请写出相关布局文件代码。</p>
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/5.jpg" class="">
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TableLayout</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">TableRow</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/TableRow1&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:id</span>=<span class="string">&quot;@+id/label&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_width</span>=<span class="string">&quot;160dp&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:text</span>=<span class="string">&quot;用户名：&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:gravity</span>=<span class="string">&quot;right&quot;</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">EditText</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:id</span>=<span class="string">&quot;@+id/input&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_width</span>=<span class="string">&quot;160dp&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">TableRow</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">TableRow</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/TableRow2&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:text</span>=<span class="string">&quot;确定&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">        <span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:text</span>=<span class="string">&quot;取消&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">TableRow</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">TableLayout</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>创建工程，命名为 RelativeLayoutDemo，布局界面如图，组件请使用相对布局排列，请写出相关布局文件代码。</p>
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/6.png" class="">
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">RelativeLayout</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/label&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:text</span>=<span class="string">&quot;用户名：&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">EditText</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/entry&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_below</span>=<span class="string">&quot;@id/label&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:text</span>=<span class="string">&quot;确认&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_toLeftOf</span>=<span class="string">&quot;@id/cancel&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_alignTop</span>=<span class="string">&quot;@id/cancel&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_toStartOf</span>=<span class="string">&quot;@id/cancel&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/cancel&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:text</span>=<span class="string">&quot;取消&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_below</span>=<span class="string">&quot;@id/entry&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_alignParentRight</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_alignParentEnd</span>=<span class="string">&quot;true&quot;</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">RelativeLayout</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>创建工程，命名为 AbsoluteLayoutDemo，布局界面如图，组件请使用绝对布局排列，请写出相关布局文件代码。</p>
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/7.png" class=""></li>
</ol>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">AbsoluteLayout</span> <span class="attr">xmlns:android</span>=<span class="string">&quot;http://schemas.android.com/apk/res/android&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/absolute&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;match_parent&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_x</span>=<span class="string">&quot;89dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_y</span>=<span class="string">&quot;165dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:text</span>=<span class="string">&quot;@string/username&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">EditText</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;218dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_x</span>=<span class="string">&quot;89dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_y</span>=<span class="string">&quot;184dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:inputType</span>=<span class="string">&quot;textPersonName&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/button3&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;100dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_x</span>=<span class="string">&quot;89dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_y</span>=<span class="string">&quot;246dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:text</span>=<span class="string">&quot;@string/confirm&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:textAllCaps</span>=<span class="string">&quot;false&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/button4&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;100dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_x</span>=<span class="string">&quot;207dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_y</span>=<span class="string">&quot;245dp&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:text</span>=<span class="string">&quot;@string/cancel&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:textAllCaps</span>=<span class="string">&quot;false&quot;</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">AbsoluteLayout</span>&gt;</span></span><br></pre></td></tr></table></figure>

<ol start="8">
<li><p>导入“OptionMenu”的安卓程序，建立如下图所示的界面，界面包含 TextView(id:TextView01)控件和菜单，并单击相应菜单项时 TextView 显示相应菜单名称，请分别在 main.xml 、main_menu.xml 和 OptionMenuActivity.java 补充程序：</p>
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/8.jpg" class="">
<p>在res&#x2F;menu下的main_menu.xml:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;utf-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">menu</span> <span class="attr">xmlns:android</span>=<span class="string">&quot;http://schemas.android.com/apk/res/android&quot;</span> &gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item0&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;打印&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">item</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item1&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;新建&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">item</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item2&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;邮件&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">item</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item3&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;设置&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">item</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item4&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;订阅&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">item</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">menu</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>java文件：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line">	<span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">onCreateOptionsMenu</span><span class="params">(Menu menu)</span> &#123;</span><br><span class="line">		<span class="type">MenuInflater</span> <span class="variable">inflater</span> <span class="operator">=</span> getMenuInflater();</span><br><span class="line">		inflater.inflate(R.menu.main_menu, menu);</span><br><span class="line">		<span class="keyword">return</span> <span class="built_in">super</span>.onCreateOptionsMenu(menu);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">onOptionsItemSelected</span><span class="params">(MenuItem item)</span> &#123;</span><br><span class="line">		<span class="type">TextView</span> <span class="variable">textView</span> <span class="operator">=</span> (TextView) findViewById(R.id.TextView01);</span><br><span class="line">		<span class="keyword">switch</span> (item.getItemId()) &#123;</span><br><span class="line">		<span class="keyword">case</span> R.id.item0:</span><br><span class="line">			textView.setText(<span class="string">&quot;打印，菜单ID：&quot;</span> + item.getItemId());</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> R.id.item1:</span><br><span class="line">			textView.setText(<span class="string">&quot;新建，菜单ID：&quot;</span> + item.getItemId());</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> R.id.item2:</span><br><span class="line">			textView.setText(<span class="string">&quot;邮件，菜单ID：&quot;</span> + item.getItemId());</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> R.id.item3:</span><br><span class="line">			textView.setText(<span class="string">&quot;设置，菜单ID：&quot;</span> + item.getItemId());</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> R.id.item4:</span><br><span class="line">			textView.setText(<span class="string">&quot;订阅，菜单ID：&quot;</span> + item.getItemId());</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">default</span>:</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> <span class="built_in">super</span>.onOptionsItemSelected(item);</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>
<p>布局文件：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/TextView01&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;MenuDemo&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>导入“SubMenu”的安卓程序，建立如下图所示的界面，界面包含 TextView(id:TextView01)控件和菜单，菜单结构如下：</p>
</li>
</ol>
<ul>
<li>设置<ul>
<li>打印</li>
</ul>
</li>
<li>新建<ul>
<li>邮件</li>
<li>订阅</li>
</ul>
</li>
</ul>
<p>并单击相应菜单项时 TextView 显示相应菜单名称， 请分别在 main.xml 、sub_menu.xml 和SubMenuActivity.java 补充程序：</p>
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/9-1.jpg" class="">
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/9-2.jpg" class="">
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/9-3.jpg" class="">

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">onCreate</span><span class="params">(Bundle savedInstanceState)</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>.onCreate(savedInstanceState);</span><br><span class="line">    setContentView(R.layout.activity_main);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">onCreateOptionsMenu</span><span class="params">(Menu menu)</span> &#123;</span><br><span class="line">    <span class="type">MenuInflater</span> <span class="variable">inflater</span> <span class="operator">=</span> getMenuInflater();</span><br><span class="line">    inflater.inflate(R.menu.sub_menu, menu);</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">super</span>.onCreateOptionsMenu(menu);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>菜单文件：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;utf-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">menu</span> <span class="attr">xmlns:android</span>=<span class="string">&quot;http://schemas.android.com/apk/res/android&quot;</span> &gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item0&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;设置&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">menu</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item2&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;打印&quot;</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">menu</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">item</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item1&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;新建&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">menu</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item3&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;邮件&quot;</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">item</span> <span class="attr">android:id</span>=<span class="string">&quot;@+id/item4&quot;</span> <span class="attr">android:title</span>=<span class="string">&quot;订阅&quot;</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">menu</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">item</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">menu</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>布局文件</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/TextView01&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/SubMenuDemo&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure>

<ol start="10">
<li>导入“ IntentDemo ” 的安卓工程， 建立如下图所示的界面，包含两个 Activity ，分别是IntentDemoActivity 和NewActivity，程序默认启动的 Activity 是IntentDemo，在用户点击“启动 Activity”按钮后，程序启动的 Activity 是 NewActivity，请分别补充程序：<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/10.png" class="">
main_activity<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/Button01&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/button&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure></li>
</ol>
<p>main_activity2</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/text&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure>

<p>MainClass:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">Button</span> <span class="variable">button</span> <span class="operator">=</span> (Button) findViewById(R.id.Button01);</span><br><span class="line">button.setOnClickListener(<span class="keyword">new</span> <span class="title class_">OnClickListener</span>() &#123;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onClick</span><span class="params">(View v)</span> &#123;</span><br><span class="line">        <span class="type">Intent</span> <span class="variable">intent</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Intent</span>(MainActivity.<span class="built_in">this</span>, IntentDemo.class);</span><br><span class="line">        startActivity(intent);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<ol start="11">
<li>导入“WebViewIntentDemo”的安卓工程，建立如下图所示的界面，布局界面如图，当用户在文本框中输入 Web 地址后，通过点击“浏览此 URL”按钮，程序根据用户输入的 Web 地址生成一个Intent，并以隐式启动的方式调用 Android 内置的 Web 浏览器，并打开指定的 Web 页面。本例输入的 Web 地址 <a target="_blank" rel="noopener" href="http://www.google.com.hk,打开页面后的效果如图/">http://www.google.com.hk，打开页面后的效果如图</a><img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/11-1.jpg" class="">
<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/11-2.jpg" class="">
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">EditText</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/editText&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:hint</span>=<span class="string">&quot;@string/text&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:inputType</span>=<span class="string">&quot;textUri&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/button&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_alignParentStart</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_below</span>=<span class="string">&quot;@+id/editText&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/button&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure></li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">final</span> <span class="type">EditText</span> <span class="variable">editText</span> <span class="operator">=</span> (EditText) findViewById(R.id.editText);</span><br><span class="line"><span class="type">Button</span> <span class="variable">button</span> <span class="operator">=</span> (Button) findViewById(R.id.button);</span><br><span class="line">button.setOnClickListener(<span class="keyword">new</span> <span class="title class_">OnClickListener</span>() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onClick</span><span class="params">(View v)</span> &#123;</span><br><span class="line">        <span class="type">String</span> <span class="variable">url</span> <span class="operator">=</span> editText.getText().toString();</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="type">Intent</span> <span class="variable">intent</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Intent</span>(Intent.ACTION_VIEW, Uri.parse(url));</span><br><span class="line">            startActivity(intent);</span><br><span class="line">        &#125; <span class="keyword">catch</span>(Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<ol start="12">
<li>导入“ActivityCommunication”的安卓工程，建立如下图所示的界面，工程将以 Sub-Activity 方式启动子Activity，及使用 Intent 进行组件间通信。<br>1)、当用户点击“启动 Activity1”和“启动 Activity2”按钮时，程序将分别启动子 SubActivity1 和SubActivity2。<br>2)、SubActivity1 提供了一个输入框，以及“接受”和“撤销”两个按钮。如果在输入框中输入信息后点击“接受”按钮，程序会把输入框中的信息传递给其父 Activity，并在父 Activity 的界面上显示。<br>3)、如果用户点击“撤销”按钮，则程序不会向父 Activity 传递任何信息。<br>4)、SubActivity2 主要是为了说明如何在父 Activity 中处理多个子 Activity，因此仅提供了用于关闭SubActivity2 的“关闭”按钮<img data-src="/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/12-1.jpg" class="">

main<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/text1&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;200dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/main_activity&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:textSize</span>=<span class="string">&quot;24sp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toTopOf</span>=<span class="string">&quot;parent&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/text2&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;16dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:textSize</span>=<span class="string">&quot;18sp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toBottomOf</span>=<span class="string">&quot;@+id/text1&quot;</span>/&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/button1&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;32dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/activity1&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:textAllCaps</span>=<span class="string">&quot;false&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toBottomOf</span>=<span class="string">&quot;@+id/text2&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/button2&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;16dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/activity2&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:textAllCaps</span>=<span class="string">&quot;false&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toBottomOf</span>=<span class="string">&quot;@+id/button1&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="type">int</span> <span class="variable">SUB1</span> <span class="operator">=</span> <span class="number">1</span>;</span><br><span class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="type">int</span> <span class="variable">SUB2</span> <span class="operator">=</span> <span class="number">2</span>;</span><br><span class="line">TextView text;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">onCreate</span><span class="params">(Bundle savedInstanceState)</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>.onCreate(savedInstanceState);</span><br><span class="line">    setContentView(R.layout.activity_main);</span><br><span class="line">    text = findViewById(R.id.text2);</span><br><span class="line"></span><br><span class="line">    findViewById(R.id.button1).setOnClickListener(<span class="keyword">new</span> <span class="title class_">View</span>.OnClickListener() &#123;</span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onClick</span><span class="params">(View v)</span> &#123;</span><br><span class="line">            <span class="type">Intent</span> <span class="variable">intent</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Intent</span>(MainActivity.<span class="built_in">this</span>, SubActivity1.class);</span><br><span class="line">            startActivityForResult(intent, SUB1);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    findViewById(R.id.button2).setOnClickListener(<span class="keyword">new</span> <span class="title class_">View</span>.OnClickListener() &#123;</span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onClick</span><span class="params">(View v)</span> &#123;</span><br><span class="line">            <span class="type">Intent</span> <span class="variable">intent</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Intent</span>(MainActivity.<span class="built_in">this</span>, SubActivity2.class);</span><br><span class="line">            startActivityForResult(intent, SUB2);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@SuppressLint(&quot;SetTextI18n&quot;)</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">onActivityResult</span><span class="params">(<span class="type">int</span> requestCode, <span class="type">int</span> resultCode, <span class="meta">@Nullable</span> Intent data)</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>.onActivityResult(requestCode, resultCode, data);</span><br><span class="line">    <span class="keyword">switch</span> (requestCode) &#123;</span><br><span class="line">        <span class="keyword">case</span> SUB1:</span><br><span class="line">            <span class="keyword">if</span> (resultCode == RESULT_OK) &#123;</span><br><span class="line">                text.setText(<span class="string">&quot;result: &quot;</span> + data.getData().toString());</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> SUB2:</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ol>
<p>activity1</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/text&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;200dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/subactivity1&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:textSize</span>=<span class="string">&quot;24sp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toTopOf</span>=<span class="string">&quot;parent&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">EditText</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/edit&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;240dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;16dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:hint</span>=<span class="string">&quot;@string/enter&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:inputType</span>=<span class="string">&quot;text&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toBottomOf</span>=<span class="string">&quot;@+id/text&quot;</span>/&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/button1&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;32dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/confirm&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:textAllCaps</span>=<span class="string">&quot;false&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toBottomOf</span>=<span class="string">&quot;@+id/edit&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/button2&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;16dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/cancel&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:textAllCaps</span>=<span class="string">&quot;false&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toBottomOf</span>=<span class="string">&quot;@+id/button1&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">EditText</span> <span class="variable">editText</span> <span class="operator">=</span> findViewById(R.id.edit);</span><br><span class="line">findViewById(R.id.button1).setOnClickListener(<span class="keyword">new</span> <span class="title class_">View</span>.OnClickListener() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onClick</span><span class="params">(View v)</span> &#123;</span><br><span class="line">        setResult(RESULT_OK, <span class="keyword">new</span> <span class="title class_">Intent</span>(<span class="literal">null</span>, Uri.parse(editText.getText().toString())));</span><br><span class="line">        finish();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">findViewById(R.id.button2).setOnClickListener(<span class="keyword">new</span> <span class="title class_">View</span>.OnClickListener() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onClick</span><span class="params">(View v)</span> &#123;</span><br><span class="line">        setResult(RESULT_CANCELED, <span class="literal">null</span>);</span><br><span class="line">        finish();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>activity2</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/text&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;200dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/subactivity2&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:textSize</span>=<span class="string">&quot;24sp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toTopOf</span>=<span class="string">&quot;parent&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">Button</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/button&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_marginTop</span>=<span class="string">&quot;32dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;@string/close&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:textAllCaps</span>=<span class="string">&quot;false&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintEnd_toEndOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintStart_toStartOf</span>=<span class="string">&quot;parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">app:layout_constraintTop_toBottomOf</span>=<span class="string">&quot;@+id/text&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">findViewById(R.id.button).setOnClickListener(<span class="keyword">new</span> <span class="title class_">View</span>.OnClickListener() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onClick</span><span class="params">(View v)</span> &#123;</span><br><span class="line">        setResult(RESULT_CANCELED, <span class="literal">null</span>);</span><br><span class="line">        finish();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>manifest:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">application</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:allowBackup</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:icon</span>=<span class="string">&quot;@mipmap/ic_launcher&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:label</span>=<span class="string">&quot;@string/app_name&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:roundIcon</span>=<span class="string">&quot;@mipmap/ic_launcher_round&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:supportsRtl</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:theme</span>=<span class="string">&quot;@style/Theme.ActivityCommunication&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">activity</span> <span class="attr">android:name</span>=<span class="string">&quot;.SubActivity2&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">activity</span> <span class="attr">android:name</span>=<span class="string">&quot;.SubActivity1&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">activity</span> <span class="attr">android:name</span>=<span class="string">&quot;.MainActivity&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">intent-filter</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">action</span> <span class="attr">android:name</span>=<span class="string">&quot;android.intent.action.MAIN&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">            <span class="tag">&lt;<span class="name">category</span> <span class="attr">android:name</span>=<span class="string">&quot;android.intent.category.LAUNCHER&quot;</span> /&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">intent-filter</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">activity</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">application</span>&gt;</span></span><br></pre></td></tr></table></figure>

<ol start="13">
<li>Spinner<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/tv&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:text</span>=<span class="string">&quot;Hello World!&quot;</span>&quot; /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">Spinner</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/spinner1&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;200dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:spinnerMode</span>=<span class="string">&quot;dropdown&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure></li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">TextView</span> <span class="variable">textView</span> <span class="operator">=</span> findViewById(R.id.tv);</span><br><span class="line"><span class="type">Spinner</span> <span class="variable">spinner</span> <span class="operator">=</span> findViewById(R.id.spinner1);</span><br><span class="line">String[] list = &#123;<span class="string">&quot;Spinner1&quot;</span>, <span class="string">&quot;Spinner2&quot;</span>, <span class="string">&quot;Spinner3&quot;</span>&#125;;</span><br><span class="line">ArrayAdapter&lt;String&gt; adapter = <span class="keyword">new</span> <span class="title class_">ArrayAdapter</span>&lt;String&gt;(<span class="built_in">this</span>,</span><br><span class="line">        android.R.layout.simple_spinner_dropdown_item, list);</span><br><span class="line">adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);</span><br><span class="line">spinner.setAdapter(adapter);</span><br><span class="line"></span><br><span class="line">spinner.setOnItemSelectedListener(<span class="keyword">new</span> <span class="title class_">AdapterView</span>.OnItemSelectedListener() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onItemSelected</span><span class="params">(AdapterView&lt;?&gt; adapterView, View view, <span class="type">int</span> i, <span class="type">long</span> l)</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (i == <span class="number">0</span>) &#123;</span><br><span class="line">            textView.setText(<span class="string">&quot;点击了Spinner1&quot;</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (i == <span class="number">1</span>) &#123;</span><br><span class="line">            textView.setText(<span class="string">&quot;点击了Spinner2&quot;</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            textView.setText(<span class="string">&quot;点击了Spinner3&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onNothingSelected</span><span class="params">(AdapterView&lt;?&gt; adapterView)</span> &#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>项目文件：<a target="_blank" rel="noopener" href="http://d0.ananas.chaoxing.com/download/5d0c3b5024bad045c70079ec9f608ba8?at_=1610294878846&ak_=86b8e2318cce2fe4e7135f92d7b7847e&ad_=0096ee08d535b1c86617b21c71d25989&fn=Android.zip">整个</a> 、 <a target="_blank" rel="noopener" href="http://115.159.109.73:8081/android1.txt">本页面源文件</a></p>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Wyatex
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://wyatex.online/%E5%A4%8D%E4%B9%A0%E9%A2%98/Android%E5%A4%8D%E4%B9%A0%E9%A2%98/" title="Android复习题">https://wyatex.online/复习题/Android复习题/</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/tags/Android/" rel="tag"># Android</a>
              <a href="/tags/%E5%A4%8D%E4%B9%A0%E9%A2%98/" rel="tag"># 复习题</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%8E%9F%E7%90%86%E7%AC%94%E8%AE%B0%EF%BC%884%EF%BC%89/" rel="prev" title="操作系统原理笔记（4）">
                  <i class="fa fa-angle-left"></i> 操作系统原理笔记（4）
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/uncategorized/java%E8%AF%BE%E5%90%8E%E9%A2%98%E6%80%BB%E7%BB%93/" rel="next" title="java课后题总结">
                  java课后题总结 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2019 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Wyatex</span>
  </div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script size="300" alpha="0.6" zIndex="-1" src="/lib/ribbon.js/dist/ribbon.min.js"></script>
  <script src="/lib/animejs/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="/lib/@next-theme/pjax/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="/lib/@fancyapps/ui/dist/fancybox/fancybox.umd.js" integrity="sha256-q8XkJ6dj5VwSvzI8+nATCHHQG+Xv/dAZBCgqmu93zOY=" crossorigin="anonymous"></script>
  <script src="/lib/lozad/dist/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="/lib/hexo-generator-searchdb/dist/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>



  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
